<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>合并调试工具</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>分片合并调试工具</h1>
    
    <div>
        <h3>1. 检查上传状态</h3>
        <input type="text" id="fileHashInput" placeholder="输入文件哈希" style="width: 500px;">
        <button onclick="checkStatus()">检查状态</button>
        <div id="statusResult"></div>
    </div>
    
    <div>
        <h3>2. 检查缺少的分片</h3>
        <button onclick="checkMissing()">检查缺少分片</button>
        <div id="missingResult"></div>
    </div>
    
    <div>
        <h3>3. 强制合并</h3>
        <button onclick="forceMerge()">强制合并</button>
        <div id="mergeResult"></div>
    </div>

    <script>
        const fileHash = '7dc42c7d9e040406304698531be0b32936117c0d5e7aac94c6c28cdffeebddad';
        document.getElementById('fileHashInput').value = fileHash;

        async function checkStatus() {
            const hash = document.getElementById('fileHashInput').value || fileHash;
            
            try {
                const response = await axios.get(`/api/upload/status/${hash}`, {
                    withCredentials: true
                });
                
                document.getElementById('statusResult').innerHTML = `
                    <h4>状态检查成功:</h4>
                    <pre>${JSON.stringify(response.data, null, 2)}</pre>
                `;
            } catch (error) {
                document.getElementById('statusResult').innerHTML = `
                    <h4>状态检查失败:</h4>
                    <pre style="color: red;">${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                `;
            }
        }

        async function checkMissing() {
            const hash = document.getElementById('fileHashInput').value || fileHash;
            
            try {
                const response = await axios.get(`/api/upload/missing/${hash}`, {
                    withCredentials: true
                });
                
                document.getElementById('missingResult').innerHTML = `
                    <h4>缺少分片检查成功:</h4>
                    <pre>${JSON.stringify(response.data, null, 2)}</pre>
                `;
            } catch (error) {
                document.getElementById('missingResult').innerHTML = `
                    <h4>缺少分片检查失败:</h4>
                    <pre style="color: red;">${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                `;
            }
        }

        async function forceMerge() {
            const hash = document.getElementById('fileHashInput').value || fileHash;
            
            try {
                const response = await axios.post('/api/upload/merge', {
                    fileHash: hash,
                    fileName: '137649199_da2-1-192.mp4',
                    totalChunks: 25,
                    fileSize: 51973319,
                    title: 'Test Video',
                    description: 'Debug test'
                }, {
                    withCredentials: true
                });
                
                document.getElementById('mergeResult').innerHTML = `
                    <h4>合并成功:</h4>
                    <pre style="color: green;">${JSON.stringify(response.data, null, 2)}</pre>
                `;
            } catch (error) {
                console.error('合并错误详情:', error);
                document.getElementById('mergeResult').innerHTML = `
                    <h4>合并失败:</h4>
                    <pre style="color: red;">${JSON.stringify(error.response?.data || error.message, null, 2)}</pre>
                    <h5>完整错误:</h5>
                    <pre style="color: red;">${JSON.stringify(error, null, 2)}</pre>
                `;
            }
        }

        // 自动检查状态
        window.onload = function() {
            checkStatus();
        };
    </script>
</body>
</html> 